2023/12/23692字符
async
- async 和 await ES7 目的是简化 Promise API 的使用,并非代替 Promise
async function promise() { //==> // const pro = new Promise((res, rej) => {
return 2; // res(2)
} // })
let pro = promise(); // pro.then(res => { return res })
console.log(pro); //--> Promise {<resolved>: 2}
await
console.log(1)
async function fn1 () {
console.log(2)
const fn3 = await function () {
return 3;
}
console.log(fn3())
}
fn1();
console.log(4); //--> 1 2 4 3